<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>资源IP变更</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/> 
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<script type="text/javascript">
		function cancel(){
			getTopWin(window).closejBox('resIpChange');
		}
		
		function change(value){
			if(value==1){
				$('#changeIp').hide();
				$("#relation").removeAttr('disabled');
			}else{
				$('#changeIp').show();
				$("#relation").attr('disabled','disabled').removeAttr('checked');
			}
		}
		
		function save(){
			var val = $("input[name='type']:checked").val();
			var entity = new Object ;
			var ipRegex = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
			if(val==1){
				$("input[name='newIp']").css('border','');
				var flag = ipRegex.exec($("input[name='newIp']").val());
				
				if($("input[name='newIp']").val()==''||flag==null){
					$("input[name='newIp']").css('border','1px solid red');
					$("input[name='newIp']").focus();
					return false;
				}
					entity.selectedVal = val;
					entity.changeIp = '';
					entity.newIp  = $("input[name='newIp']").val() ;
			}else{
				$("input[name='currentIp']").css('border','1px solid #c0c0c0');
				$("input[name='newIp']").css('border','1px solid #c0c0c0');
				
				var currentFlag = ipRegex.exec($("input[name='currentIp']").val());
				var newIpFlag   = ipRegex.exec($("input[name='newIp']").val());
				
				if($("input[name='currentIp']").val()==''||currentFlag==null){
					$("input[name='currentIp']").css('border','1px solid red');
					$("input[name='currentIp']").focus();
					return false;
				}else if($("input[name='newIp']").val()==''||newIpFlag==null){
					$("input[name='newIp']").css('border','1px solid red');
					$("input[name='newIp']").focus();
					return false;
				}else if($("input[name='currentIp']").val()==$("input[name='newIp']").val()){
					$.jBox.alert("IP相同,变更无意义!","提示",{width:140});
					return false;
				}
			
				entity.selectedVal = val;
				entity.changeIp = $("input[name='currentIp']").val();
				entity.newIp  = $("input[name='newIp']").val();
			}
				entity.relation = $('#relation').is(':checked');
			var resIpChangeWin = getTopWin(window).currentWin['resIpChange'];
			resIpChangeWin.ipChange(entity);
			getTopWin(window).closejBox('resIpChange');
		}
		
		$(document).ready(function(){
			
			var isSelect = '${isSelected}';
			if(isSelect==''){
				$("input[name='type']").eq(1).attr('checked','checked');
				$("input[name='type']").eq(0).attr('disabled','disabled');
				$("#relation").attr('disabled','disabled');
				$('#changeIp').show();
			}else{
				$("input[name='type']").eq(0).attr('checked','checked');
				$('#changeIp').hide();
			}
			
		});
		
		
	</script>
  </head>
  
  <body style="padding:5px;" >
    <fieldset style="border:1px solid #627eb7 ;margin-bottom: 5px;height:130px;" >
    	<legend >选择范围</legend>
    	<table class="table_eidt" >
			<tbody>
				<tr>
					<td  colspan="2"><input type="radio" name="type" value="1" onclick="change(this.value)" />勾选的资源 
					 <input  type="radio" name="type" value="2" onclick="change(this.value)"  />按IP变更</td>
				</tr>
				<tr>
					<td colspan="2"><input  type="checkbox" name="relation" id="relation"  />按组成关系变更(父子关系变更)</td>
				</tr>
				<tr id="changeIp" >
					<td class="td_left">变更IP</td>
					<td class="td_right" ><input type="text" name="currentIp" id="" class="input_text" maxlength="15" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeypress="if((event.keyCode<46 || event.keyCode>57 )) event.returnValue=false" /></td>
				</tr>
				<tr>
					<td class="td_left" >新IP</td>
					<td class="td_right" ><input type="text" name="newIp" class="input_text" maxlength="15" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeypress="if((event.keyCode<46 || event.keyCode>57 )) event.returnValue=false" /> </td>
				</tr>
			</tbody>
		</table>
    </fieldset>
	<div class="btn-div" >
   			<input type="button" value="保存" onclick="save()" class="btn-4"  /> 
   			<input type="button" value="取消" onclick="cancel()" class="btn-4" />
	</div>
  </body>
</html>
